package cn.biplam.front.html.base;

import java.util.Iterator;
import java.util.Map.Entry;

import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.common.wrapper.KvMap;

/**
 * Html页面属性集
 * @author 	WangSong
 * @create 	2009-3-21 上午10:19:25
 * @version 1.0
 */
public final class HtmlProperty {
	
	/**页面属性集合 */
	private KvMap<String,String> kvmProperty=null;
	
	public HtmlProperty(){
		this.kvmProperty=new KvMap<String, String>();
	}

	/**
	 * 功能：获取对象及其内容的 HTML 形式
	 * @return
	 * @throws ErrorMessage
	 */
	public String draw() throws ErrorMessage {
		StringBuilder sb = new StringBuilder();
		this.getContent(sb);
		return sb.toString();
	}

	/**
	 * 功能：获取位于对象起始和结束标签内的 HTML
	 * @param sb
	 * @throws ErrorMessage
	 */
	protected void getContent(StringBuilder sb) throws ErrorMessage {
		Iterator<Entry<String, String>> ite = kvmProperty.getIterator();
		Entry<String, String> entry;
		while(ite.hasNext()){
			entry = ite.next();
			sb.append(entry.getKey());
			sb.append("='");
			sb.append(entry.getValue());
			sb.append("' ");
		}
	}
	
	/**
	 * 功能：返回对象的页面属性值
	 * @param propertyName
	 * @return
	 */
	public String getProperty(String propertyName) {
		return kvmProperty.getByKey(propertyName);
	}

	/**
	 * 功能：返回对象的页面属性集合
	 * @return
	 */
	public KvMap<String, String> getPropertySet() {
		return kvmProperty;
	}

	/**
	 * 功能：设置对象的页面属性值
	 * @param propertyName			页面属性名称
	 * @param propertyValue		页面属性值
	 * @throws ErrorMessage
	 */
	public void setProperty(String propertyName,String propertyValue) throws ErrorMessage {
		this.kvmProperty.put(propertyName, propertyValue);
	}

	/**
	 * 功能：设置对象的页面属性集合
	 * @param kvmProperty
	 */
	public void setPropertySet(KvMap<String, String> kvmProperty) {
		this.kvmProperty = kvmProperty;
	}


}
